﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ignitron.EEngine.Maths;
using SharpDX;

namespace Ignitron.EEngine.Adapters.DX.Helper
{
    /// <summary>
    /// SharpDX Conversion helper class
    /// </summary>
    public static class Helper
    {
        public static Vector3 ToDX(this EVector3 vec)
        {
            return new Vector3(vec.X, vec.Y, vec.Z);
        }


        public static Vector4 ToDX(this EVector4 vec)
        {
            return new Vector4(vec.X, vec.Y, vec.Z, vec.W);
        }

        //public static Matrix ToDX(this EMatrix4 mat)
        //{
        //    return new Matrix(mat.Column0.X, mat.Column0.Y, mat.Column0.Z, mat.Column0.W,
        //        mat.Column1.X, mat.Column1.Y, mat.Column1.Z, mat.Column1.W,
        //        mat.Column2.X, mat.Column2.Y, mat.Column2.Z, mat.Column2.W,
        //        mat.Column3.X, mat.Column3.Y, mat.Column3.Z, mat.Column3.W);
        //}

        public static Matrix ToDX(this EMatrix4 mat)
        {
            return new Matrix(mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W,
                mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W,
                mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W,
                mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W);
        }


        public static Vector3 ToLHS(this Vector3 vec)
        {
            return new Vector3(vec.X, vec.Y, vec.Z);
        }

        //public static Vector3 ToLHS(this Vector3 vec)
        //{
        //    return new Vector3(vec.X, vec.Y, -vec.Z);
        //}

        public static EVector3 ToEE(this Vector3 vec)
        {
            return new EVector3(vec.X, vec.Y, vec.Z);
        }

        public static EVector4 ToEE(this Vector4 vec)
        {
            return new EVector4(vec.X, vec.Y, vec.Z, vec.W);
        }

        public static EMatrix4 ToEE(this Matrix mat)
        {
            var matOut = new EMatrix4(mat.Column1.X, mat.Column1.Y, mat.Column1.Z, mat.Column1.W,
                mat.Column2.X, mat.Column2.Y, mat.Column2.Z, mat.Column2.W,
                mat.Column3.X, mat.Column3.Y, mat.Column3.Z, mat.Column3.W,
                mat.Column4.X, mat.Column4.Y, mat.Column4.Z, mat.Column4.W);
            // HACK: Why do we need for DX transposed matrix
            matOut.Transpose();
            return matOut;
        }

        //public static EMatrix4 ToEE(this Matrix mat)
        //{
        //    var matOut = new EMatrix4(mat.Column1.X, mat.Column1.Y, mat.Column1.Z, mat.Column1.W,
        //        mat.Column2.X, mat.Column2.Y, mat.Column2.Z, mat.Column2.W,
        //        mat.Column3.X, mat.Column3.Y, mat.Column3.Z, mat.Column3.W,
        //        mat.Column4.X, mat.Column4.Y, mat.Column4.Z, mat.Column4.W);
        //    return matOut;
        //}

    }
}
